<template>
    <d2-container type="card">
        <header>
            <el-form :inline="true" :model="selectFrom" class="demo-form-inline" size="mini">
                <el-form-item label="店铺">
                    <el-select v-model="selectFrom.shopId" filterable placeholder="请选择店铺">
                        <el-option v-for="item in shopList" :key="item.id" :label="item.name" :value="item.id">
                        </el-option>
                    </el-select>
                </el-form-item>
                <el-form-item>
                    <el-button type="primary"  @click="getShopCommodityData()">查询</el-button>
                    <el-button type="primary">新增</el-button>
                </el-form-item>
            </el-form>
        </header>
        <footer>
            <el-table :data="tableData" border style="width: 100%" size="mini" :height="height">
                
                <el-table-column label="商品名称" prop="name" align="center"></el-table-column>
                <el-table-column label="销量" prop="salesVolume" align="center"></el-table-column>
                <el-table-column label="原价" prop="originalPrice" align="center"></el-table-column>
                <el-table-column label="会员价	" prop="memberPrice" align="center"></el-table-column>
                <el-table-column label="店铺名称" align="center">
                    <template slot-scope="scope">
                        {{ scope.row.shopInfo.name }}
                    </template>
                </el-table-column>
                <el-table-column label="创建时间" prop="createTime" align="center"></el-table-column>
            </el-table>
            <div class="block" style="text-align:center">
                <el-pagination @size-change="handleSizeChange" @current-change="handleCurrentChange" :current-page="page"
                    :page-sizes="[5, 10, 15, 20]" :page-size="limit" layout="total, sizes, prev, pager, next, jumper"
                    :total="total">
                </el-pagination>
            </div>
        </footer>
    </d2-container>
</template>
  
<script>
import { getShopInfoBack } from "@/api/modules/shop_info.js"
import { getShopCommodity } from "@/api/modules/shop_commodity.js"
export default {
    name: 'shopInfo',
    data() {
        return {
            selectFrom: {},//搜索栏
            tableData: [],//表格数据
            page: 1,
            limit: 10,
            total: 0,
            height: window.innerHeight - 250, //表格高度
            shopList: [],//商店表
        }
    },
    mounted() {
        this.getShopInfoBackData();
        this.getShopCommodityData();
        //-------------------------表格响应----------------//
        this.createHeight();
        //当页面发生变化时，表格高度固定
        window.onresize = () => {
            return (() => {
                this.$nextTick(() => {
                    this.createHeight();
                });
            })();
        };
    },
    methods: {
        //获取商品数据
        getShopInfoBackData() {
            getShopInfoBack({}).then(res => {
                this.shopList = res.dataList;
            })
        },
        //获取店铺商品商品数据
        getShopCommodityData() {
            this.selectFrom.page = this.page;
            this.selectFrom.limit = this.limit;
            getShopCommodity(this.selectFrom).then(res => {
                this.tableData = res.dataList;
                this.total = res.total;
            })
        },
        handleSizeChange(val) {
            this.limit = val;
        },
        handleCurrentChange(val) {
            this.page = val;
        },
        //---------------自动变更表格高度------------------//
        createHeight() {
            this.height = window.innerHeight - 250;
        }
    }
}
</script>
  